home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / btrieve / bunxex.exe / BTRCOIG.C next >
C/C++ Source or Header  |  1993-12-02  |  4KB  |  173 lines

  1. /* Copyright (c) 1993 NOVELL            */
  2. /* All Rights Reserved.                */
  3. /* create, open, insert and get sample program     */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. extern unsigned int NWErrno;  /*cs 9/8/93 */
  10.  
  11. /*#pragma pack (1)*/    /* must do this, one byte boundary alignment */
  12.  
  13. /*#define int short*/   /* must do this, define int to be two bytes */
  14.  
  15. #define BIN 0x0004
  16.  
  17. #ifndef USHORT
  18. typedef unsigned short USHORT;
  19. #endif
  20. #ifndef PSZ
  21. typedef unsigned char *PSZ;
  22. #endif
  23. #ifndef PUSHORT
  24. typedef unsigned short *PUSHORT;
  25. #endif
  26. #ifndef UCHAR
  27. typedef unsigned char UCHAR;
  28. #endif
  29. #ifndef CHAR
  30. typedef char CHAR;
  31. #endif
  32.  
  33. typedef struct {
  34.    short nKeyPos;
  35.    short nKeyLen;
  36.    short nKeyFlag;
  37.    char notUsed1[4];
  38.    char KeyType;
  39.    char reserve1[5];
  40. }  KEYSPEC;
  41.  
  42. typedef struct {
  43.    short nRecLen;
  44.    short nPageSize;
  45.    short nIndexCount;
  46.    char notUsed2[4];
  47.    short nFileFlags;
  48.    char reserve2[2];
  49.    short nPreAlloc;
  50.    KEYSPEC KeySpecBuf[1];
  51. } FILESPEC;
  52.  
  53. typedef struct {
  54.    char Last_Name[20];
  55.    char First_Name[30];
  56.    short ID;
  57.    char Social_Sec[12];
  58. } EMPLOY_REC;
  59.  
  60. FILESPEC FileSpecBuf;
  61. /*char szFileName[] = "AUSCSHAWHP\\SYS:\\PATIENT2\\btrcoig.dat";*/
  62. char szFileName[128];
  63. char sPosBlk[128];
  64. unsigned short nBufLen;
  65.  
  66. EMPLOY_REC Employ;
  67. char sKeyBuf[128];
  68.  
  69. main (argc, argv)
  70. int argc;
  71. char *argv[];
  72. {
  73.    int i;
  74.    int iStatus;
  75.  
  76.  
  77.    if (argc != 2)
  78.    {
  79.      printf("\nUsage: btrcoig <Server\\\\vol:\\\\dir\\\\file>\n");
  80.      return;
  81.    }
  82.  
  83.    strcpy(szFileName, argv[1]);
  84.    printf ("\n**** Test creating btrcoig.dat file ****\n");
  85.  
  86. /* create files */
  87.    memset(&FileSpecBuf, 0, sizeof(FILESPEC));
  88.    FileSpecBuf.nRecLen = 64;
  89.    FileSpecBuf.nPageSize = 2048;  
  90.    FileSpecBuf.nFileFlags = 0;
  91.    FileSpecBuf.nIndexCount = 1;
  92.    FileSpecBuf.KeySpecBuf[0].nKeyPos = 51;
  93.    FileSpecBuf.KeySpecBuf[0].nKeyLen = 2;
  94.    FileSpecBuf.KeySpecBuf[0].nKeyFlag = BIN;
  95.    FileSpecBuf.KeySpecBuf[0].KeyType = 1;
  96.  
  97.    nBufLen = sizeof(FILESPEC);
  98.  
  99.    iStatus = BTRV(14, sPosBlk, &FileSpecBuf, &nBufLen, szFileName, 0);
  100.    if (iStatus)
  101.    {
  102.       printf("create file failed\n");
  103.       printf("iStatus = %d\n", iStatus); 
  104.       printf("\n NWErrno=%lx \n", NWErrno);
  105.    }
  106. /* end create file */
  107.  
  108.    printf("Test opening btrcoig.dat file\n");
  109.    nBufLen = sizeof(EMPLOY_REC);
  110.    iStatus = BTRV(0, sPosBlk, &Employ, &nBufLen, szFileName , 0);
  111.    if (iStatus)
  112.    {
  113.       printf("open file failed\n");
  114.       printf("iStatus = %d\n", iStatus);
  115.       printf("\n NWErrno=%lx \n", NWErrno);
  116.    }
  117. /*end open file*/
  118.  
  119.    printf("Test inserting Employ record\n");
  120.    strcpy(Employ.Last_Name,"Shaw");
  121.    strcpy(Employ.First_Name,"Charles");
  122.    Employ.ID = 1;
  123.    strcpy(Employ.Social_Sec, "123-45-6789");
  124.  
  125.    printf("Employ.Last_Name=%s\n",Employ.Last_Name);
  126.    printf("Employ.First_Name=%s\n",Employ.First_Name);
  127.    printf("EmPloy.ID=%d\n",Employ.ID);
  128.    printf("Employ.Social_Sec=%s\n",Employ.Social_Sec);
  129.  
  130.    nBufLen = sizeof(EMPLOY_REC);
  131.    iStatus = BTRV(2, sPosBlk, &Employ, &nBufLen, sKeyBuf, 0);
  132.    if (iStatus)
  133.    {
  134.       printf("Insert Employ record failed\n");
  135.       printf("iStatus = %d\n", iStatus);
  136.       printf("\n NWErrno=%lx \n", NWErrno);
  137.    }
  138. /*end insert Employ record */
  139.  
  140.    printf("Test getting Employ record\n");
  141.    Employ.Last_Name[0]='\0';
  142.    Employ.First_Name[0]='\0';
  143.    Employ.ID = 0;
  144.    Employ.Social_Sec[0]='\0';
  145.  
  146.    *((short *)&sKeyBuf[0]) = 1;
  147.    nBufLen = sizeof(EMPLOY_REC);
  148.    iStatus = BTRV(5, sPosBlk, &Employ, &nBufLen, sKeyBuf, 0);
  149.    if (iStatus)
  150.    {
  151.       printf("Get Employ record failed\n");
  152.       printf("iStatus = %d\n", iStatus);
  153.       printf("\n NWErrno=%lx \n", NWErrno);
  154.    }
  155.  
  156.    printf("Employ.Last_Name=%s\n",Employ.Last_Name);
  157.    printf("Employ.First_Name=%s\n",Employ.First_Name);
  158.    printf("EmPloy.ID=%d\n",Employ.ID);
  159.    printf("Employ.Social_Sec=%s\n",Employ.Social_Sec);
  160. /*end get Employ record */
  161.  
  162.    printf("Testing close opened file\n");
  163.    iStatus = BTRV(1, sPosBlk, &Employ, &nBufLen, sKeyBuf, 0);
  164.    if (iStatus)
  165.    {
  166.       printf("Closing file failed\n");
  167.       printf("iStatus = %d\n", iStatus);
  168.       printf("\n NWErrno=%lx \n", NWErrno);
  169.    }
  170. /*end close opened file */   
  171.  
  172. }
  173.